package model

import (
	"time"

	"gorm.io/gorm"
)

// Message 消息模型
type Message struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
	Title     string         `gorm:"size:128;not null;comment:标题" json:"title"`
	Content   string         `gorm:"type:text;comment:内容" json:"content"`
	Type      int            `gorm:"default:0;comment:消息类型(0:系统通知,1:待办事项)" json:"type"`
	Status    int            `gorm:"default:0;comment:状态(0:未读,1:已读)" json:"status"`
	UserID    uint           `gorm:"index;not null;comment:用户ID" json:"user_id"`
	ReadTime  *time.Time     `gorm:"comment:阅读时间" json:"read_time"`
}

// TableName 设置表名
func (Message) TableName() string {
	return "go_message"
}

// MessageSearchParams 消息搜索参数
type MessageSearchParams struct {
	Title  string `form:"title" json:"title"`
	Type   int    `form:"type" json:"type"`
	Status int    `form:"status" json:"status"`
	UserID uint   `form:"user_id" json:"user_id"`
}

// CreateMessageRequest 创建消息请求
type CreateMessageRequest struct {
	Title   string `json:"title" binding:"required,max=128"`
	Content string `json:"content" binding:"required"`
	Type    int    `json:"type" binding:"omitempty,oneof=0 1"`
	UserID  uint   `json:"user_id" binding:"required"`
}

// UpdateMessageRequest 更新消息请求
type UpdateMessageRequest struct {
	Title   string `json:"title" binding:"omitempty,max=128"`
	Content string `json:"content" binding:"omitempty"`
	Type    int    `json:"type" binding:"omitempty,oneof=0 1"`
	Status  int    `json:"status" binding:"omitempty,oneof=0 1"`
}
